unit uDependentes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, upai, FMTBcd, SqlExpr, Provider, DB, DBClient, DBCtrls,
  StdCtrls, Mask, JvExMask, JvToolEdit, JvMaskEdit, JvCheckedMaskEdit,
  JvDatePickerEdit, Buttons, ExtCtrls, ComCtrls;

type
  TfDependentes = class(TfPai)
    pnl1: TPanel;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    chk1: TCheckBox;
    Data2: TJvDatePickerEdit;
    dbcbbGRAU_PARENTESCO: TDBComboBox;
    dbedtNOME_DEP: TDBEdit;
    BitBtn10: TBitBtn;
    BitBtn11: TBitBtn;
    BitBtn12: TBitBtn;
    BitBtn13: TBitBtn;
    dsDep: TClientDataSet;
    dsDepID_DEPENDENTES: TIntegerField;
    dsDepCOD_IMALU: TIntegerField;
    dsDepNOME_DEP: TStringField;
    dsDepDATA_NASC: TDateField;
    dsDepIRRF: TStringField;
    dsDepDEP_PERMANENTE: TStringField;
    dsDepCURSANDO_FAC: TStringField;
    dsDepDEFIC_FISICO: TStringField;
    dsDepGRAU_PARENTESCO: TStringField;
    dDepend: TDataSetProvider;
    sDep: TSQLDataSet;
    sDepID_DEPENDENTES: TIntegerField;
    sDepCOD_IMALU: TIntegerField;
    sDepNOME_DEP: TStringField;
    sDepDATA_NASC: TDateField;
    sDepIRRF: TStringField;
    sDepDEP_PERMANENTE: TStringField;
    sDepCURSANDO_FAC: TStringField;
    sDepDEFIC_FISICO: TStringField;
    sDepGRAU_PARENTESCO: TStringField;
    procedure btngravarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fDependentes: TfDependentes;
  vCodImob, vIdDep : Integer;
  vTipo : string;

implementation

uses UDM;

{$R *.dfm}

procedure TfDependentes.btngravarClick(Sender: TObject);
begin
   if dm.c_6_genid.Active then
     dm.c_6_genid.Close;
   dm.c_6_genid.CommandText := 'SELECT CAST(GEN_ID(gen_dependente, 1) as INTEGER) AS CODIGO FROM RDB$DATABASE';
   dm.c_6_genid.Open;
   dsDepID_DEPENDENTES.AsInteger := dm.c_6_genidCODIGO.AsInteger;
   dm.c_6_genid.Close;


  if (chk1.Checked = True) then
    dsDepIRRF.AsString := 'S';
  dsDepCOD_IMALU.AsInteger := vCodImob;
  dsDepDATA_NASC.AsDateTime := Data2.Date;
   
  inherited;

end;

procedure TfDependentes.FormShow(Sender: TObject);
begin
  inherited;
  chk1.Checked := False;
  
  if (vTipo = 'NOVO') then
     btnIncluir.Click;
  if (vTipo = 'ALTERAR') then
  begin
    dsDep.Params[0].AsInteger := vIdDep;
    dsDep.Open;
  end;
end;

end.
